<template>
	<view class="team">
		
		<view class="searchWrap " style="display: flex;">
			<view style="position: relative;height:60rpx;width: 700rpx;">
				<input @confirm="search" v-model="searchValue" class="searchInput fs18" placeholder="寻找心仪商品" type="text" value="" />
				<image @click="search" style="width: 50upx;height: 50upx;top: 18upx;position: absolute;right: 60upx;z-index: 999;" src="/static/images/search2.png" mode=""></image>
			</view>
			
			<!-- <view class="complete" @click="complete()" style="">完成</view> -->
		</view>
		
		
		<view class="contentFix">
			<view class="contentLeft">
				<view :class="[(active3 == index3)?'active3':'']" class="contentLeftLi" @click="tab3(index3,item.gc_id)" v-for="(item,index3) in classList" :key="index3">{{item.gc_name}}</view>								
			</view>
			<view class="contentRight">
				<view class="contentRight">
				
					<view class="contentRightB">
						<view v-for="(item,index5) in goodsList" :key="index5" class="li">
							<view style="display: flex;" class="">
								<view style="width: 126upx;height: 106upx;" class="">
									<image style="width: 106upx;height: 106upx;" :src="item.goods_image_url" mode=""></image>
								</view>
								<view style="height: 106upx;" class="">
									<view style="line-height: 50upx;width: 330upx;" class="fs18 C333 oneLine">{{item.goods_name}}</view>
									<view style="line-height: 30upx;" class=" Cff0101">价格：￥{{item.goods_price}} </view>
									<view style="line-height: 30upx;" class=" Cff0101">佣金：￥{{item.commission}} </view>
								</view>
							</view>
							<view style="transform: scale(0.6);margin-top: 10upx;" class="">
								<evan-switch active-color="#4cd964" @change="switchBtn(item.goods_id,item.check)" v-model="item.check"></evan-switch>
								<!-- <switch checked color="#4cd964" @change="switch1Change;" /> -->
							</view>
						</view>
					</view>
				</view>
			</view>			
		</view>		
	</view>
	
</template>

<script>
	import evanSwitch from "@/member/components/evan-switch/evan-switch.vue"
	export default {
		components:{
			evanSwitch
		},
		data() {
			return {
				obj:{},
				flag:false,
				checked:true,
				addGoods:[],
				delGoods:[],
				searchValue:"",
				curpage:1,
				hasmore:false,
				classList:[],
				goodsList:[],
				lis:[0,1,2,3,4],
				active1:0,
				active3:0,
				active2flag:2,
				
			}
		},
		onShow() {
			
		},
		onLoad() {
			this.getLis()
		},
		onNavigationBarButtonTap() {
			
		},
		onReachBottom() {
			if(this.hasmore){
				this.curpage++
				this.$util.request({
					url: '/mobile/index.php?act=distribution&op=getShopGoodsSelectList',
					method: 'get',
					data: {
						"curpage":this.curpage,
						"gc_id":gc_id
					},
				}).then((res)=> {						
					this.goodsList=this.goodsList.concat(res.datas.goodsList) 
					// this.goodsList=res.datas.goodsList
					for(var i=0;i<this.goodsList.length;i++){
						this.goodsList[i].check=this.goodsList[i].is_added == 1 ? true : false
					}
					if(this.goodsList.length == 0){
						uni.showToast({
							title:"没有更多数据",
							icon:"none"
						})
					}
					this.curpage=res.datas.pageInfo.curpage
					this.hasmore=res.datas.pageInfo.hasmore
				})
			}else{
				uni.showToast({
					title:"没有更多数据",
					icon:"none"
				})
			}
		},
		methods: {
			complete(){
				this.delGoods=[]
				this.addGoods=[]
				for(let j=0;j<this.goodsList.length;j++){
					if(Boolean(this.goodsList[j].is_added) !=this.goodsList[j].check ){
						if(Boolean(this.goodsList[j].is_added)){
							this.delGoods.push(this.goodsList[j].goods_id)
						}else{
							this.addGoods.push(this.goodsList[j].goods_id)
						}
					}
				}
				
				this.$util.request({
					url: '/mobile/index.php?act=distribution&op=submitShopGoods',
					method: 'post',
					data: {
						"addGoods":this.addGoods,
						"delGoods":this.delGoods
					},
				}).then((res)=> {						
					if(res.error_code == 0){
						uni.showToast({
							title:"保存成功",
							icon:"none"
						})
						setTimeout(()=>{
							this.getLis()
						},2000)
					}else{
						uni.showToast({
							title:res.message,
							icon:"none"
						})
					}
				})
			},
			switchBtn(id,check){
				let delId="";
				let addId="";
				if(check){
					 addId=id					
				}else{
					 delId=id
				}
				
				this.$util.request({
					url: '/mobile/index.php?act=distribution&op=submitShopGoods',
					method: 'post',
					data: {
						"addGoods":addId,
						"delGoods":delId
					},
				}).then((res)=> {						
					if(res.error_code == 0){
						uni.showToast({
							title:"保存成功",
							icon:"none"
						})
						// setTimeout(()=>{
						// 	this.getLis()
						// },2000)
					}else{
						uni.showToast({
							title:res.message,
							icon:"none"
						})
					}
				})
				
				
				// console.log(id,check)			
				// this.obj[id]=check
				
				// for(let i in this.obj){
				// 	if(this.obj[i]){
				// 		this.addGoods.push(i)
				// 	}else{
				// 		this.delGoods.push(i)
				// 	}
				// }
			},
			search(){
				this.curpage=1
				this.$util.request({
					url: '/mobile/index.php?act=distribution&op=getShopGoodsSelectList',
					method: 'get',
					data: {
						"curpage":this.curpage,
						"keyword":this.searchValue
					},
				}).then((res)=> {						
					this.goodsList=res.datas.goodsList
					for(var i=0;i<this.goodsList.length;i++){
						this.goodsList[i].check=this.goodsList[i].is_added == 1 ? true : false
					}
					if(this.goodsList.length == 0){
						uni.showToast({
							title:"没有更多数据",
							icon:"none"
						})
					}
					this.curpage=res.datas.pageInfo.curpage
					this.hasmore=res.datas.pageInfo.hasmore
				})
			},
			 switch1Change: function (e) {
			            console.log('switch1 发生 change 事件，携带值为', e.target.value)
			        },
			getLis(){
				this.$util.request({
					url: '/mobile/index.php?act=distribution&op=getShopGoodsSelectList',
					method: 'get',
					data: {
				
					},
				}).then((res)=> {						
					this.classList=res.datas.classList
					var gc_id=res.datas.classList[0].gc_id
					this.$util.request({
						url: '/mobile/index.php?act=distribution&op=getShopGoodsSelectList',
						method: 'get',
						data: {
							"curpage":this.curpage,
							"gc_id":gc_id
						},
					}).then((res)=> {							
						this.goodsList=res.datas.goodsList
						for(var i=0;i<this.goodsList.length;i++){
							this.goodsList[i].check=this.goodsList[i].is_added == 1 ? true : false
						}
						

						if(this.goodsList.length == 0){
							uni.showToast({
								title:"没有更多数据",
								icon:"none"
							})
						}
						this.curpage=res.datas.pageInfo.curpage
						this.hasmore=res.datas.pageInfo.hasmore
					})
				})
			},	
			tab3(index,gc_id){
				this.active3=index
				this.$util.request({
					url: '/mobile/index.php?act=distribution&op=getShopGoodsSelectList',
					method: 'get',
					data: {
						"curpage":this.curpage,
						"gc_id":gc_id
					},
				}).then((res)=> {						
					this.goodsList=res.datas.goodsList
					for(var i=0;i<this.goodsList.length;i++){
						this.goodsList[i].check=this.goodsList[i].is_added == 1 ? true : false
					}
					if(this.goodsList.length == 0){
						uni.showToast({
							title:"没有更多数据",
							icon:"none"
						})
					}
					this.curpage=res.datas.pageInfo.curpage
					this.hasmore=res.datas.pageInfo.hasmore
				})
			},			
			tab2(index,url){
				this.active2flag=index				
				uni.switchTab({
					url:url
				})
			}			
		}
	}
</script>

<style>	
	.status_bar {
	    height: var(--status-bar-height);  
	    width: 100%;  
	    background-color: #f5f5f5;
	}  
	.top_view {  
	    height: var(--status-bar-height);  
	    width: 100%;  
	    position: fixed;  
	    background-color: #f5f5f5;  
	    top: 0;  
	    z-index: 999;  
	}
	.lh20{
		line-height: 20upx;
		height: 20upx;
	}
	.lh25{
		line-height: 25upx;
	}
	.lh30{
		line-height: 30upx;
	}
	.lh35{
		line-height: 35upx;
	}
	.lh40{
		line-height: 40upx;
	}
	.lh45{
		line-height: 45upx;
	}
	.lh50{
		line-height: 50upx;
	}
	.lh100{
		line-height: 100upx;
	}
	.C000{
		color: #000000;
	}
	.Ce13d97{
		color: #ff4300;
	}
	.Cfe0000{
		color: #ff4300;
	}
	.Cc06{
		color: #ff4300;
	}
	.mt55mb30{
		margin-top: 55upx;
		margin-bottom: 30upx;
	}
	.Cfff{
		color: #FFFFFF;
	}

	.flex{		
		display: flex;
		flex-direction: row;
		justify-content: space-between;
		align-content: space-between;
	}
	.paddingL20{
		padding-left: 20upx;
	}
	.C999{
		color:#999 ;
	}
	.Cff0101{
		color:#ff0101 ;
	}
	.Cc00251{
		color: #c00251;
	}
	.strick{
		text-decoration: line-through;
	}
	.Cfe0000{
		color: #ff4300;
	}
	.line1{
		width: 430upx;
	}
	.hide{
		display: none;
	}
	.marginB20{
		margin-bottom: 20upx;
	}
	
	.twoline{
	   overflow : hidden;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-line-clamp: 2;
		-webkit-box-orient: vertical;
	}
	.pl20{
		padding-left: 20upx;
	}
	.positionT{
		position: relative;
		top: 50upx;
	}
	.paddingB15{
		padding-bottom: 15upx;
	}
	.borderB{
		border-bottom: 1px solid #f4f4f6;
	}
	.borderT{
		border-top: 1px solid #f4f4f6;
	}
	.gl{
		position: absolute;
		right: 30upx;
	}
	.pr30{
		padding-right: 30upx;
	}
	.C333{
		color: #333333;
	}
	.C666{
		color: #666666;
	}
	.Cf00{
		color: #ff0000;
	}
	
	.bold{
		font-weight: bold;
	}
	.C1d1d1d{
		color:#1d1d1d ;
	}
	.fl{
		float: left;
	}
	.fr{
		float: right;
	}
	.tac{
		text-align: center;
	}
	.Ce5258e{
		color: #e5258e;
	}
	.Cccc{
		color: #CCCCCC;
	}
	.Cff0101{
		color: #ff0101;
	}
	uni-page-body {
		
	}		
	.fs30{
		/* font-size: 30upx */
		font-size: 45upx
	}
	.fs26{
		font-size:39upx
		/* font-size: 26upx */
	}
	.fs12{
		font-size: 18upx
		/* font-size: 12upx */
	}
	.fs16{
		font-size: 24upx
		/* font-size: 16upx */
	}
	.fs14{
		font-size: 21upx
		/* font-size: 14upx */
	}
	.fs15{
		font-size: 22.5upx
		/* font-size: 15upx */
	}
	.fs27{
		font-size: 40.5upx
		/* font-size: 27upx */
	}
	.fs18{
		font-size: 27upx
		/* font-size: 18upx */
	}
	.fs28{
		font-size: 42upx
		/* font-size: 28upx */
	}
	.fs10{
		font-size: 15upx
		/* font-size: 10upx */
	}
	.fs30{
		font-size: 45upx
		/* font-size: 28upx */
	}
	.fs24{
		font-size: 36upx
		/* font-size: 24upx */
	}
	.fs20{
		font-size:30upx
		/* font-size: 20upx */
	}
	.fs22{
		font-size:33upx
		/* font-size: 22upx */
	}
	.fs21{
		font-size: 31.5upx
		/* font-size: 21upx */
	}
	
	.bottom{
		box-sizing: border-box;
		padding: 0 10upx;
		background-color: #FFFFFF;
		position: fixed;
		z-index: 99999999999;
		left: 0;
		bottom: 0;
		height: 98upx;
		width: 100%;
		box-shadow: 0upx -1upx 10upx rgba(0,0,0,0.8);
		display: flex;
		flex-direction: row;
		justify-content: space-around;
	}
	.bottom view{
		font-size: 27upx;
		color: #666;
		text-align: center;
		margin-top: -4upx;
	}
	.bottom view.active2{
		color: #ff4300;
	}
	.bottom image{
		position: relative;
		top: 15upx;
		width: 48upx;
		height: 48upx;
	}
	.title2{
		margin-top: 76upx;
		margin-bottom: 0upx;
		height: 35px;
		padding-left: 20upx
	}
	.oneLine{
		text-overflow: ellipsis;
		overflow: hidden;
		white-space: nowrap;
	}
	.Ce5007e{
		color: #e5007e;
	}
	.team{
		background-color: #F4F4F4;		
	}
	.active1{
		color: #ff4300;
	}
	.contentFix{
	/* 	position: fixed;
		left: 0;
		top: 80upx;
		bottom: 100upx;
		right: 0; */
		width: 100%;
		/* background-color: #F0AD4E; */
	}
	.contentLeft{		
		overflow-y: scroll;
	/* 	position: fixed;
		left: 0;
		top: 85upx;
		bottom: 100upx;
		right: 0; */
		background-color: #f5f5f5;
		width: 160upx;
		box-sizing: border-box;
		/* #ifdef H5 */
		/* height:90vh; */
		/* #endif */
		/* #ifdef APP-PLUS */
		/* height:80vh; */
		/* #endif */	
	}
	.contentLeftLi{
		font-size: 27upx;
		width: 160upx;
		height: 80upx;
		line-height: 80upx;	
		text-align: center;
		background-color: #f5f5f5;
		margin-bottom: 1px;
	}
	.active3{
		background-color: #fff;
	}
	.contentRight{
		overflow-y: scroll;
		position: fixed;
		left: 160upx;
		top: 170upx;
		/* #ifdef MP-WEIXIN */
		top: 7A0upx;
		/* #endif */
		bottom: 100upx;
		right: 0;
		width: 690upx;
		box-sizing: border-box;
		background-color: #f5f5f5;
		/* padding: 0upx 20upx 0 20upx; */
	}
	.searchWrap{
		padding: 0rpx 20rpx;
		z-index: 10;
		height: 84upx;
		/* width: 550upx; */
	}
	.searchWrap input{
		border-radius: 10upx;
		padding-left: 20upx;
		box-sizing: border-box;
		position: absolute;
		top: 10upx;
		z-index: 666;
		width: 550upx;
		height: 64upx;
		border:2upx solid #D2D2D2;		
	}
	.contentRightB{
		overflow-y: scroll;
		/* position: fixed; */
		left: 160upx;
		/* #ifdef MP-WEIXIN */
			top: 53upx;
		/* #endif */
		/* #ifndef MP-WEIXIN */
			top: 150rpx;
		/* #endif */
		bottom: 100upx;
		right: 0;
		width: 690upx;
		box-sizing: border-box;
		/* padding: 0upx 20upx 0 20upx; */
	}
	.contentRightB .li{
		width: 540upx;
		display: flex;
		justify-content: space-between;
		align-content: center;
		padding: 20upx 0;
		border-bottom: 1upx solid #CCCCCC;
	}
	.complete{
		font-size: 30rpx;font-weight: bold; padding: 0rpx 20rpx;background-color: #ff4300;margin: 10rpx 0;color: #FFFFFF;height: 60rpx;border-radius: 15rpx;line-height: 60rpx;
	}
</style>
